<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page contentType="text/html; charset=gb2312"%>
<%@page import="com.tss.util.*"%>
<%@page import="com.store.*"%>
<%@page import="java.util.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
User just_user = (User)session.getAttribute("LoginUser");
if (!just_user.hasPower("10811")) {
	out.println(strNoPowerInfo); 
	return;
}
User user = (User)session.getAttribute("LoginUser");
List list = null;
String cmd = ParamUtils.getParameter(request,"cmd","");
String strErr = "";
String author_id   = "";
String author_name = "";
if (user != null && !user.getId().trim().equals("")) {
	author_id = user.getId();
	author_name = user.getUserName();
}
String soft_name     = ParamUtils.getParameter(request,"soft_name","");
String soft_desc     = ParamUtils.getParameter(request,"soft_desc","");
String category_id   = ParamUtils.getParameter(request,"category_id","");
String parent_id   = ParamUtils.getParameter(request,"parent_id","");
String soft_size     = ParamUtils.getParameter(request,"soft_size","0");
String soft_type     = ParamUtils.getParameter(request,"soft_type","");
String[] os_type     = ParamUtils.getParameters(request,"os_type");
String soft_language = ParamUtils.getParameter(request,"soft_language","");
String commend_level = ParamUtils.getParameter(request,"commend_level","0");
String download_url  = ParamUtils.getParameter(request,"download_url","");

DownCateMgr cateMgr = new DownCateMgr();

if (cmd.trim().equals("insert")) {
	if (strErr.trim().equals("") && soft_name.trim().equals("")) {
		strErr = "软件名称不能为空!";
	}
	if (strErr.trim().equals("") && soft_desc.length() >= 100) {
		strErr = "软件描述不能超过100字符!";
	}
	if (strErr.trim().equals("") && category_id.trim().equals("")) {
		strErr = "请选择软件所属分类!";
	}
	if (strErr.trim().equals("")) {
		try {
			Integer.parseInt(soft_size);
		}
		catch(Exception ex) {
			strErr = "软件大小必须为整数!";
		}
	}
	if (strErr.trim().equals("")) {
		try {
			Integer.parseInt(commend_level);
		}
		catch(Exception ex) {
			strErr = "推荐等级必须为整数!";
		}
	}
	if (strErr.trim().equals("") && download_url.trim().equals("")) {
		strErr = "下载地址不能为空!";
	}

	if (strErr.trim().equals("")) {
		Download download = new Download();
		download.setSoftName(soft_name);
		download.setAuthorId(author_id);
		download.setAuthorName(author_name);
		download.setSoftDesc(soft_desc);
		download.setCategoryId(category_id);
		download.setSoftSize(Integer.parseInt(soft_size));
		download.setSoftType(soft_type);
		download.setOsType(os_type);
		download.setSoftLanguage(soft_language);
		download.setCommendLevel(Integer.parseInt(commend_level));
		download.setDownloadUrl(download_url);
		download.setIssueTime(TSSDate.fullTime());
		download.setHit(0);
		download.insert();
		if (download.hasErr()) strErr = download.getErrHtml();
	}
}
%>
<html>
<head>
	<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
   	<title>指定审批代理人</title>
   	<script language="javascript">
   function clk_submit() {
	var oForm = document.operatorForm;
	if (oForm.soft_name.value == "") {
		alert("软件名称不能为空!");
		oForm.soft_name.focus();
		return false;
	}
	if (oForm.download_url.value == "") {
		alert("下载地址不能为空!");
		oForm.download_url.focus();
		return false;
	}
	if (oForm.category_id.selectedIndex < 0) {
		alert("请选择软件所属分类!");
		oForm.category_id.focus();
		return false;
	}
	oForm.cmd.value = "insert";
	return true;
}

function upload_file() {
	var oForm = document.operatorForm;
	var r = window.showModalDialog('../selectFrm.htm','knowledge_mgt/soft_upload.jsp','dialogHeight: 200px;dialogWidth: 300px; center: yes; status:no;help: no');
	if(r && r != "") {
		oForm.download_url.value = r;
	}
}


   </script>

</head>

<body bgcolor="#FFFFFF" leftmargin="5" topmargin="5" marginwidth="5" marginheight="5" scroll="yes">

  <form name="operatorForm" method="post" onsubmit="return clk_submit();">
  	<table width="90%" border="0" cellpadding="0" cellspacing="1" >
   <tr> 
          <td height="31" valign="top" background="images/title_bk_01.gif" style="padding-left:10px;padding-top:6px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%" style="color:#FFFFFF;font-size:13px;">
                  <b>知识库</b> -&gt; 
                  <b>软件添加</b>
                </td>
                <td width="50%" align="right" style="padding-right:10px;">&nbsp;
                  <span onclick="right_menu_clk('know_soft_list.jsp');" style="cursor:hand;color:#FFFFFF;font-size:12px;text-de--ation: underline;">软件列表</span>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr> 
          <td height="100" align="center" valign="top" style="padding-top:20px;padding-bottom:10px;">
            <table width="80%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
            
              <%if (!strErr.trim().equals("")) {%>
              <tr> 
                <td width="30%" height="28" align="right" bgcolor="#858585"><font color="#FFFFFF">错误提示：</font></td>
                <td bgcolor="#EDEDF0"><font color=red><%=strErr%></font>&nbsp;</td>
              </tr>
              <%}%>
              <tr> 
                <td width="30%" height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">软件名称：</font></td>
                <td bgcolor="#D7D7DB"><input name="soft_name" type="text" class="inputbox" value="<%=soft_name%>" size="30" maxlength="50"></td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">软件所属分类：</font></td>
                <td bgcolor="#EDEDF0">
                  <select name="parent_id" onChange="operatorForm.submit();">
                    <option value="">请选择</option>
                    <%
                    list = cateMgr.get(" and is_leaf=0","order_id");
                    if (list != null && list.size() > 0) {
                    	for(int i=0;i<list.size();i++) {
                    		DownCate item = (DownCate)list.get(i);
                    %>
                    <option value="<%=item.getId()%>"<%if (item.getId().equals(parent_id)){%> selected<%}%>><%=item.getCategoryName()%></option>
                    <%
                    	}
                    }
                    %>
                  </select>
                  -->
                   <select name="category_id" >
                  
                    <%
                    list = cateMgr.get(" and parent_id='"+parent_id+"' and is_leaf=1","order_id");
                    if (list != null && list.size() > 0) {
                    	for(int i=0;i<list.size();i++) {
                    		DownCate item = (DownCate)list.get(i);
                    %>
                    <option value="<%=item.getId()%>"<%if (item.getId().equals(category_id)){%> selected<%}%>><%=item.getCategoryName()%></option>
                    <%
                    	}
                    }
                    %>
                  </select>
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">软件大小：</font></td>
                <td bgcolor="#EDEDF0">
                  <input name="soft_size" type="text" class="inputbox" value="<%=soft_size%>" size="5" maxlength="10"> (K) &nbsp; 
                  授权类型：
                  <select name="soft_type">
                    <%for(int i = 0; i < soft_type_info.length;i++){%>
                    <option value="<%=soft_type_info[i]%>"<%if (soft_type_info[i].equals(soft_type)){%> selected<%}%>><%=soft_type_info[i]%></option>
                    <%}%>
                  </select> &nbsp; 
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">运行环境：</font></td>
                <td bgcolor="#EDEDF0">
                  <%for(int i=0;i<os_type_info.length;i++){%>
                  <input type="checkbox" name="os_type" value="<%=os_type_info[i]%>"<%if (ParamUtils.inArray(os_type_info[i],os_type)){%> checked<%}%>> <%=os_type_info[i]%> &nbsp;
                  <%}%>
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">软件描述：</font></td>
                <td bgcolor="#EDEDF0">
                  <textarea name="soft_desc" cols="40" rows="5"><%=soft_desc%></textarea>
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">语言界面：</font></td>
                <td bgcolor="#EDEDF0">
                  <select name="soft_language">
                    <%
                    for(int i=0;i<soft_language_info.length;i++) {
                    %>
                    <option value="<%=soft_language_info[i]%>"<%if (soft_language_info[i].equals(soft_language)){%> selected<%}%>><%=soft_language_info[i]%></option>
                    <%}%>
                  </select> &nbsp; 
                  推荐等级：
                  <select name="commend_level">
                    <%
                    String levelStar = "★★★★★★★★★★★★★★★";
                    for(int i=1;i<=commentLevel;i++) {
                    %>
                    <option value="<%=i%>"<%if (commend_level.equals(i+"")){%> selected<%}%>><%=levelStar.substring(0,i)%></option>
                    <%}%>
                  </select>
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">下载地址：</font></td>
                <td bgcolor="#EDEDF0">
                  <input name="download_url" type="text" class="inputbox" value="<%=download_url%>" size="45" maxlength="100" readonly="readonly"   style="background-color:#EDEDE8">
                  <input type="button" value="上传附件" class="inputButton" onclick="upload_file();"> 
                </td>
              </tr>
  			 <tr> 
                <td height="24" align="right" bgcolor="#EDEDF0">&nbsp;</td>
                <td bgcolor="#EDEDF0"> 
                  <input type="submit" name="button" value="提 交" class="inputButton"> 
                  <input type="reset" name="reset" value="重 写" class="inputButton"> 
                  <input type="hidden" name="cmd" value=""> 
                </td>
              </tr>
  </table>
   </td>
   </tr>
   </table>
   </form>

 



<%if (cmd.equals("insert") && strErr.trim().equals("")){%>
<script language="javascript">
alert("软件信息添加成功!");
location.href = "know_soft_list.jsp";
</script>
<%}%>
</body>
</html>
